<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #outer {
            width: 500px;
            margin: 100px auto;
            padding: 10px;
            background-color: #333;
            border-radius: 10px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="outer">
        <p id="info" style="color: white;">一共5张，当前第1张</p>

        <img src="../images/11.jpg" width="500px" alt="">

        <button id="prev">上一张</button>
        <button id="next">下一张</button>
    </div>
</body>
<script>
    window.onload = function () {
        var prev = document.getElementById("prev");
        var next = document.getElementById("next");
        var img = document.getElementsByTagName("img")[0];
        var imgArr = ["../images/11.jpg", "../images/12.jpg", "../images/13.jpg", "../images/14.jpg", "../images/15.jpg"];
        var index = 0;

        var info = document.getElementById("info");

        prev.onclick = function () {
            index--;
            if (index < 0) {
                index = imgArr.length - 1;
            }
            img.src = imgArr[index];

            info.innerHTML = "一共" + imgArr.length + "张，当前第" + (index + 1) + "张";
        };
        next.onclick = function () {
            index++;
            if (index > imgArr.length - 1) {
                index = 0;
            }
            img.src = imgArr[index];

            info.innerHTML = "一共" + imgArr.length + "张，当前第" + (index + 1) + "张";
        };
    }
</script>

</html>